﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FileDeleteNew
{
    public partial class MainForm : Form
    {
        Form1 picform = new Form1();
        LogDelForm logform = new LogDelForm();
        public MainForm()
        {
            InitializeComponent();
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            this.ShowInTaskbar = true;
            FormLoad(picform);
            FormLoad(logform);
        }
        private void btn_PicDelete_Click(object sender, EventArgs e)
        {
            FormLoad(picform);
        }
        private void btn_LogDelete_Click(object sender, EventArgs e)
        {
            FormLoad(logform);
        }
        public void FormLoad(Form form)
        {
            this.panel1.Controls.Clear();
            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            this.panel1.Controls.Add(form);
            form.Show();
        }
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)//当用户点击窗体右上角X按钮或(Alt + F4)时 发生           
            {
                e.Cancel = true;
                //this.ShowInTaskbar = false;
                this.notifyIcon1.Icon = this.Icon;
                this.Hide();
            }
        }
        private void ts_Show_Click(object sender, EventArgs e)
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            this.StartPosition = FormStartPosition.CenterScreen;
        }
        private void ts_Close_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(
            "窗口关闭后，后台文件删除任务即将停止！是否现在关闭窗口",
            "提示",
            MessageBoxButtons.OKCancel,
            MessageBoxIcon.Question) != DialogResult.OK)
            {
                //e.Cancel = true;
                return;
            }
            System.Environment.Exit(0);
        }
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Visible = true;
                this.WindowState = FormWindowState.Normal;
            }
        }


    }
}
